package com.listviewdemo.event;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;

/**
 * Created by tzj on 2018/4/26.
 */
public class AddViewEvent extends Event<AddViewEvent> {
    public static final String NAME = "addView";
    public static final String KEY = "key";

    private int position = -1;

    public AddViewEvent(int viewTag,int position) {
        super(viewTag);
        this.position = position;
    }

    @Override
    public boolean canCoalesce() {
        return false;
    }

    @Override
    public String getEventName() {
        return NAME;
    }
    public int getPosition() {
        return position;
    }
    @Override
    public void dispatch(RCTEventEmitter rctEventEmitter) {
        rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeEventData());
    }

    private WritableMap serializeEventData() {
        WritableMap eventData = Arguments.createMap();
        eventData.putInt(KEY,getPosition());
        return eventData;
    }

}
